<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\SmsLog;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SmsLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SmsLog(), function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->disableActions();
            $grid->column('id')->sortable();
            $grid->column('phone');
            $grid->column('code')->copyable();
            $grid->column('add_ip');
            $grid->status->using([0 => '未使用', 1 => '已使用'])->label(
                [
                    '0' => '#6E6B6B',
                    '1' => '#00C33C',
                ]
            );
            $grid->column('add_time');
            $grid->column('use_time');
             $grid->model()->orderBy('id','desc');
            // 设置表单提示值
            $grid->quickSearch('phone')->placeholder('请输入手机号');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('phone');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SmsLog(), function (Show $show) {
            $show->field('id');
            $show->field('phone');
            $show->field('code');
            $show->field('add_ip');
            $show->field('status');
            $show->field('add_time');
            $show->field('use_time');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SmsLog(), function (Form $form) {
            $form->display('id');
            $form->text('phone');
            $form->text('code');
            $form->text('add_ip');
            $form->text('status');
            $form->text('add_time');
            $form->text('use_time');
        });
    }
}
